﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abble1
{
    class Program
    {
        static void Main(string[] args)
        {
            Text7();
        }

        static void Text()
        {

        }
        //用户输入正方形边长，用*打印出实心正方形。
        static void Text1()
        {
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }

        //打印九九乘法表
        static void Text2()
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}*{1}={2}\t", i, j, i * j);
                    if (i == j)
                    {
                        Console.Write("\n");
                    }
                }
            }
        }

        //打印空心正方形
        static void Text3()
        {
            Console.WriteLine("请输入空心正方形边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= a; j++)
                {
                    if ((i == 1 || i == a) || (j == 1 || j == a))
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();
            }
        }
        //打印菱形
        static void Text4()
        {
            Console.WriteLine("请输入菱形行数：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 1; i <= (a + 1) / 2; i++)//打印上半部分
            {
                for (int j = (a - 1) / 2; j >= i; j--)//打印空格
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)//打印*号, i行   i*2-1   个*号
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }

            for (int i = (a - 1) / 2; i >= 1; i--)
            {
                for (int j = i - 1; j < (a - 1) / 2; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }

        }

        //打印杨辉三角形
        static void Text5()
        {
            int[,] arr = new int[10, 10];
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if (j == 0 || j == i)
                    {
                        arr[i, j] = 1;
                    }
                    else
                    {
                        arr[i, j] = arr[i - 1, j - 1] + arr[i - 1, j];
                    }
                    Console.Write("{0}", arr[i, j]);
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
        }


        //在 Main 方法中创建一个字符串类型的数组，
        //并存入 5 个值，然后将数组中下标是偶数的元素输出。
        static void Text6()
        {
            int[] arr = new int[5];
            arr[0] = 100;
            arr[1] = 13;
            arr[2] = 45;
            arr[3] = 60;
            arr[4] = 77;

            Console.WriteLine("数组元素有；");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i]+" ");
            }
            Console.WriteLine();
            Console.WriteLine("下标是偶数的元素有；");
            for (int i = 0; i < arr.Length; i++)
            {
                if (i%2 == 0)
                {
                    Console.Write(arr[i] + " ");
                }
            }
        }

        //如果一个数组保存元素是有序的（从大到小），向这个数组中插入一个数，使得插入后的数组元素仍然保持有序。
        static void Text7()
        {
            int[] arr = new int[6];
            arr[0] = 100;
            arr[1] = 12;
            arr[2] = 54;
            arr[3] = 23;
            arr[4] = 10;

            Console.WriteLine("原数组：");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i]+" ");
                
            }
            Console.WriteLine();

            Console.WriteLine("请输入一个数：");
            arr[5] = int.Parse(Console.ReadLine());

            Array.Sort(arr);
            Array.Reverse(arr);
            Console.WriteLine("排序后：");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " ");
            }
            
        }

    }
}